<?php
/**
 * Created by PhpStorm.
 * User: Thinkpad
 * Date: 2015/6/24
 * Time: 15:09
 */
namespace Home\Controller;
use Think\Controller;

class SearchController extends CommonController{

    private $Cart='';
    private $Goods='';

    function __construct()
    {
        parent::__construct();
        $this->Cart=D("Cart");
        $this->Goods=D("Goods");
        $this->userID=session("userID");
    }

    function index()
    {
        if($_POST)
        {
            $map['name']=array('LIKE','%'.$_POST['search'].'%');
            $SearchProduct=$this->Goods->where($map)->select();
            $this->assign("SearchProduct",$SearchProduct);
        }

        $cartNum=$this->Cart->where("user_id=".$this->userID)->sum('number');
        $this->assign("cartNum",$cartNum);
        $cartNumPrice=$this->Cart->where("user_id=".$this->userID)->select();
        $cartPrice='';
        foreach($cartNumPrice as $key=>$r)
        {
            $cartPrice += $r['shop_price']*$r['number'];
        }
        $this->assign("cartPrice",$cartPrice);
        $this->display();
    }
}